
var flag  = false;

// load Animate
function LoadDiv(){
	var sp_node = document.createElement("div");
	var place = GetTranstionPlace();
	sp_node.classList.add("box");
	sp_node.style.top = (place[0]-100)+"px";
	sp_node.style.left = (place[1]-100)+"px";
	
	if(flag == true){
		//change color
		sp_node.style.backgroundColor = "#"+GetRandomColor();
	}
	
	document.body.appendChild(sp_node);
	AppendAnimate(sp_node);
	GetRandomColor();
}

// Div transition to remove
function AppendAnimate(sp_node){
	$(sp_node).animate({
		'opacity':1,
		'width':'100px',
		'height':'100px'
	},5000,function(){
		DivClear(sp_node);
	})
}
function DivClear(sp_node){
	$(sp_node).animate({
		'opacity':0,
		'width':'1px',
		'height':'1px'
	},5000,function(){
		sp_node.remove();
	})
}

// get place
function GetTranstionPlace(){
	var sum = new Array();
	sum[0] = document.body.clientHeight;
	sum[1] = document.body.clientWidth;
	var y_and_x = new Array();
	y_and_x[0] = Math.floor(Math.random()*sum[0]);
	y_and_x[1] = Math.floor(Math.random()*sum[1]);
	return y_and_x;
}

//get RandomColor
function GetRandomColor(){
	var ran_str = '0123456789abcdef';
	var random_color = '';
	for(let i = 0;i < 6;i++){
		random_color += ran_str.charAt(Math.floor(Math.random()*15));
	}
	return random_color;
}
$(document).keydown(function(){
	if(event.keyCode = 13){
		if(flag == false){
			flag = true;
		}else{
			flag = false;
		}
	}
	
})

setInterval('LoadDiv()','100')